package com.example.rankscore;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class Start extends Activity {
	ArrayList<Item_start> arr_game = new ArrayList<Item_start>();
	Lv_arrayadapter adapter_lv = null;
	ListView Lv_game = null;
	SQLiteDatabase database = null;

	private void CallNewActivity(int id) {
		Intent Intent_ttkm = new Intent(Start.this, Option_game.class);
		Bundle bundle = new Bundle();
		bundle.putInt("id", id);
		Intent_ttkm.putExtra("ttkmPackage", bundle);
		startActivity(Intent_ttkm);
	}

	public void loaddatabase() {

//		database = openOrCreateDatabase("rankscoredb.s3db",
//				SQLiteDatabase.CREATE_IF_NECESSARY, null);
//		Cursor cur = database.query("Game", null, null, null, null, null, null);
//		cur.moveToFirst();
		arr_game = new ArrayList<Item_start>();
//		while (cur.isAfterLast() == false) {
//			Item_start game = new Item_start();
//			game.setIdGame(cur.getInt(0));
//			game.setNameGame(cur.getString(1));
//			game.setNumPlayers(cur.getInt(2));
//			arr_game.add(game);
//			cur.moveToNext();
//		}
//		cur.close();
		Item_start game1 = new Item_start();
		game1.setIdGame(1);
		game1.setNameGame("Tiến Lên Miền Nam");
		game1.setNumPlayers(4);
		arr_game.add(game1);
		Item_start game2 = new Item_start();
		game2.setIdGame(2);
		game2.setNameGame("Phỏm");
		game2.setNumPlayers(4);
		arr_game.add(game2);
		Item_start game3 = new Item_start();
		game3.setIdGame(2);
		game3.setNameGame("Phỏm");
		game3.setNumPlayers(4);
		arr_game.add(game3);
		Item_start game4 = new Item_start();
		game4.setIdGame(2);
		game4.setNameGame("Phỏm");
		game4.setNumPlayers(4);
		arr_game.add(game4);
		Item_start game5 = new Item_start();
		game5.setIdGame(2);
		game5.setNameGame("Phỏm");
		game5.setNumPlayers(4);
		arr_game.add(game5);
		Item_start game6 = new Item_start();
		game6.setIdGame(2);
		game6.setNameGame("Phỏm");
		game6.setNumPlayers(4);
		arr_game.add(game6);
		Item_start game7 = new Item_start();
		game7.setIdGame(2);
		game7.setNameGame("Phỏm");
		game7.setNumPlayers(4);
		arr_game.add(game7);
		
		Lv_game = (ListView) findViewById(R.id.lv_game);
		// Khởi tạo đối tượng adapter và gán Data source
		adapter_lv = new Lv_arrayadapter(this, R.layout.item_start,// lấy
																	// custom
																	// layout
				arr_game/* thiết lập data source */);
		Lv_game.setAdapter(adapter_lv);// gán Adapter vào Lisview

	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_start);
		loaddatabase();
		Lv_game.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// truyền ID thông tin khuyến mãi của Item được click vào
				CallNewActivity(arr_game.get(position).getIdGame());
			}
		});
	}
}
